home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / programming / c / sipp / include / sipp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1978-11-24  |  8.9 KB  |  320 lines

  1. /**
  2.  ** sipp - SImple Polygon Processor
  3.  **
  4.  **  A general 3d graphic package
  5.  **
  6.  **  Copyright Equivalent Software HB  1992
  7.  **
  8.  ** This program is free software; you can redistribute it and/or modify
  9.  ** it under the terms of the GNU General Public License as published by
  10.  ** the Free Software Foundation; either version 1, or any later version.
  11.  ** This program is distributed in the hope that it will be useful,
  12.  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ** GNU General Public License for more details.
  15.  ** You can receive a copy of the GNU General Public License from the
  16.  ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  **/
  18.  
  19. /**
  20.  ** sipp.h - Public inteface to the sipp rendering library.
  21.  **/
  22.  
  23.  
  24. #ifndef _SIPP_H
  25. #define _SIPP_H
  26.  
  27. #include <geometric.h>
  28.  
  29.  
  30. #ifndef M_PI
  31. #define M_PI 3.1415926535897932384626
  32. #endif
  33.  
  34. #ifndef FALSE
  35. typedef int bool;
  36. #define FALSE  0
  37. #define TRUE   1
  38. #endif 
  39.  
  40. /*
  41.  * Customize for those that don't have memcpy() and friends, but
  42.  * have bcopy() instead.
  43.  */
  44.  
  45. #ifdef NOMEMCPY
  46. #define memcpy(to, from, n) bcopy((from), (to), (n))
  47. #endif
  48.  
  49.  
  50. /*
  51.  * The macro RANDOM() should return a random number
  52.  * in the range [-1, 1].
  53.  */
  54. #include <stdlib.h>
  55. #include <machine/limits.h>
  56. #define RANDOM()  (2.0 * ((float)random())/((float)LONG_MAX) - 1.0)
  57.  
  58.  
  59. /*
  60.  * Modes for rendering
  61.  */
  62. #define PHONG      0
  63. #define GOURAUD    1
  64. #define FLAT       2
  65. #define LINE       3
  66.  
  67.  
  68. /*
  69.  * Field definition.
  70.  */
  71. #define EVEN   0
  72. #define ODD    1
  73. #define BOTH   2
  74.  
  75.  
  76. /*
  77.  * Types of lightsources.
  78.  */
  79. #define LIGHT_DIRECTION    0
  80. #define LIGHT_POINT        1
  81.  
  82. /*
  83.  * Types of spotlights (actually lightsource types too).
  84.  */
  85. #define SPOT_SHARP   2
  86. #define SPOT_SOFT    3
  87.  
  88.  
  89. /*
  90.  * Interface to shader functions.
  91.  */
  92. typedef void Shader();
  93.  
  94.  
  95. /*
  96.  * Colors are handled as an rgb-triple
  97.  * with values between 0 and 1.
  98.  */
  99. typedef struct {
  100.     double   red;
  101.     double   grn;
  102.     double   blu;
  103. } Color;
  104.  
  105.  
  106. /*
  107.  * Structure storing the vertices in surfaces. The vertices for a
  108.  * surface are stored in a binary tree sorted first on x, then y and last z.
  109.  */
  110. typedef struct vertex_t {
  111.     Vector            pos;    /* vertex position */
  112.     Vector            normal;    /* average normal at vertex */
  113.     Vector            texture;    /* texture parameters (if any) */
  114.     struct vertex_t  *big, *sml;  /* pointers to children in the tree */
  115. } Vertex;
  116.  
  117.  
  118. /*
  119.  * Polygon definition. A polygon is defined by a list of
  120.  * references to its vertices (counterclockwize order).
  121.  */
  122. typedef struct polygon_t {
  123.     int         nvertices;
  124.     Vertex    **vertex;
  125.     bool        backface;   /* polygon is backfacing (used at rendering) */
  126.     struct polygon_t *next;
  127. } Polygon;
  128.  
  129.  
  130. /*
  131.  * Surface definition. Each surface consists of a vertex tree, 
  132.  * a polygon list, a pointer to a surface description and a pointer
  133.  * to a shader function.
  134.  */
  135. typedef struct surface_t {
  136.     Vertex           *vertices;          /* vertex tree */
  137.     Polygon          *polygons;          /* polygon list */
  138.     void             *surface;           /* surface description */
  139.     Shader           *shader;            /* shader function */
  140. /*    Vector            max, min;          / * Bounding box (Future use) */
  141.     int               ref_count;         /* no of references to this surface */
  142.     struct surface_t *next;              /* next surface in the list */
  143. } Surface;
  144.  
  145.  
  146. /*
  147.  * Object definition. Object consists of one or more
  148.  * surfaces and/or one or more subojects. Each object
  149.  * has its own transformation matrix that affects itself
  150.  * and all its subobjects.
  151.  */
  152. typedef struct object_t {
  153.     Surface         *surfaces;       /* List of surfaces */
  154.     struct object_t *sub_obj;        /* List of subobjects */
  155.     Transf_mat       transf;         /* Transformation matrix */
  156.     int              ref_count;      /* No of references to this object */
  157.     struct object_t *next;           /* Next object in this list */
  158. } Object;
  159.  
  160.  
  161.  
  162. /*
  163.  * Information needed in a lightsource to generate
  164.  * shadows.
  165.  */
  166. typedef struct {
  167.     Transf_mat  matrix;
  168.     double      fov_factor;
  169.     double      bias;
  170.     bool        active;
  171.     float      *d_map;
  172. } Shadow_info;
  173.  
  174.  
  175. /*
  176.  * Public part of lightsource definition.
  177.  * Used for both normal lightsources and spotlights.
  178.  */
  179. typedef struct lightsource_t {
  180.     Color                 color;      /* Color of the lightsource */
  181.     bool                  active;     /* Is the light on? */
  182.     int                   type;       /* Type of lightsource */
  183.     void                 *info;       /* Type dependent info */
  184.     Shadow_info           shadow;     /* Shadow information */
  185.     struct lightsource_t *next;       /* next lightsource in the list */
  186. } Lightsource;
  187.  
  188.  
  189. /*
  190.  * Virtual camera definition
  191.  */
  192. typedef struct {
  193.     Vector position;     /* camera position */
  194.     Vector lookat;       /* point to look at */
  195.     Vector up;           /* Up direction in the view */ 
  196.     double focal_ratio;
  197. } Camera;
  198.  
  199.  
  200. /*
  201.  * Surface description used by the basic shader. This shader
  202.  * does simple shading of surfaces of a single color.
  203.  */
  204. typedef struct {
  205.     double  ambient;       /* Fraction of color visible in ambient light */
  206.     double  specular;      /* Fraction of colour specularly reflected */
  207.     double  c3;            /* "Shinyness" 0 = shiny,  1 = dull */
  208.     Color   color;         /* Colour of the surface */
  209.     Color   opacity;       /* Opacity of the surface */
  210. } Surf_desc;
  211.  
  212.  
  213. extern char  * SIPP_VERSION;
  214.  
  215.  
  216. /*
  217.  * The world that is rendered. Defined in objects.c
  218.  */
  219. extern Object  *sipp_world;
  220.  
  221.  
  222. /*
  223.  * The internal (default) camera.
  224.  */
  225. extern Camera  *sipp_camera;
  226.  
  227.  
  228. /*
  229.  * This defines all public functions implemented in sipp.
  230.  */
  231.  
  232. /* Global initialization and configuration functions. */
  233. extern void          sipp_init();
  234. extern void          sipp_show_backfaces();
  235. extern void          sipp_shadows();
  236. extern void          sipp_background();
  237.  
  238. /* Functions for handling surfaces and objects. */
  239. extern void          vertex_push();
  240. extern void          vertex_tx_push();
  241. extern void          polygon_push();
  242. extern Surface      *surface_create();
  243. extern Surface      *surface_basic_create();
  244. extern void          surface_set_shader();
  245. extern void          surface_basic_shader();
  246. extern Object       *object_create();
  247. extern Object       *object_instance();
  248. extern Object       *object_dup();
  249. extern Object       *object_deep_dup();
  250. extern void          object_delete();
  251. extern void          object_add_surface();
  252. extern void          object_sub_surface();
  253. extern void          object_add_subobj();
  254. extern void          object_sub_subobj();
  255.  
  256. /* Functions for handling transforming objects. */
  257. extern void          object_set_transf();
  258. extern Transf_mat   *object_get_transf();
  259. extern void          object_clear_transf();
  260. extern void          object_transform();
  261. extern void          object_rot_x();
  262. extern void          object_rot_y();
  263. extern void          object_rot_z();
  264. extern void          object_rot();
  265. extern void          object_scale();
  266. extern void          object_move();
  267.  
  268. /* Functions for handling lightsources and spotlights. */
  269. extern Lightsource  *lightsource_create();
  270. extern Lightsource  *spotlight_create();
  271. extern void          light_destruct();
  272. extern void          lightsource_put();
  273. extern void          spotlight_pos();
  274. extern void          spotlight_at();
  275. extern void          spotlight_opening();
  276. extern void          spotlight_shadows();
  277. extern void          light_color();
  278. extern void          light_active();
  279. extern double        light_eval();
  280.  
  281. /* Functions for handling the viewpoint and virtual cameras. */
  282. extern Camera       *camera_create();
  283. extern void          camera_destruct();
  284. extern void          camera_pos();
  285. extern void          camera_at();
  286. extern void          camera_up();
  287. extern void          camera_focal();
  288. extern void          camera_params();
  289. extern void          camera_use();
  290.  
  291. /* Functions to render an image. */
  292. extern void          render_image_file();
  293. extern void          render_image_func();
  294. extern void          render_field_file();
  295. extern void          render_field_func();
  296.  
  297. /* The basic shader. */
  298. extern void          basic_shader();
  299.  
  300.  
  301. /*
  302.  * The following macros are provided for backward compatibility.
  303.  * We plan to remove them from future releases though,
  304.  * so we don't encourage use of them.
  305.  */
  306. #define object_install(obj)    object_add_subobj(sipp_world, obj);
  307. #define object_uninstall(obj)  object_sub_subobj(sipp_world, obj);
  308. #define view_from(x, y, z)     camera_position(sipp_camera, x, y, z)
  309. #define view_at(x, y, z)       camera_look_at(sipp_camera, x, y, z)
  310. #define view_up(x, y, z)       camera_up(sipp_camera, x, y, z)
  311. #define view_focal(fr)         camera_focal(sipp_camera, fr)
  312. #define viewpoint(x, y, z, x2, y2, z2, ux, uy, uz, fr)\
  313.     camera_params(sipp_camera, x, y, z, x2, y2, z2, ux, uy, uz, fr)
  314. #define lightsource_push(x, y, z, i) \
  315.     lightsource_create(x, y, z, i, i, i, LIGHT_DIRECTION)
  316. #define render_image_pixmap(w, h, p, f, m, o) \
  317.     render_image_func(w, h, f, p, m, o)
  318.  
  319. #endif /* _SIPP_H */
  320.